package com.frank.oj.controller.admin;

import com.frank.model.entity.judge.Judge;
import com.frank.oj.common.result.CommonResult;
import com.frank.oj.service.admin.rejudge.RejudgeService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author frank
 * @Date 2024/5/6
 */
@RestController
@RequestMapping("/api/admin/judge")
@RequiresAuthentication
@RequiresRoles("root")
@RequiresPermissions("rejudge")
public class AdminJudgeController {

    @Resource
    private RejudgeService rejudgeService;

    /**
     * 重判
     */
    @GetMapping("rejudge")
    public CommonResult<Judge> rejudge(@RequestParam("submitId") Long submitId) {
        return rejudgeService.rejudge(submitId);
    }

    /**
     * 重判比赛题目
     */
    @GetMapping("/rejudge-contest-problem")
    public CommonResult<Void> rejudgeContestProblem(@RequestParam("cid") Long cid, @RequestParam("pid") Long pid) {
        return rejudgeService.rejudgeContestProblem(cid, pid);
    }

    /**
     * 手动判题
     */
    @GetMapping("/manual-judge")
    public CommonResult<Judge> manualJudge(@RequestParam("submitId") Long submitId,
                                           @RequestParam("status") Integer status,
                                           @RequestParam(value = "score", required = false) Integer score) {
        return rejudgeService.manualJudge(submitId, status, score);
    }

    /**
     * 取消判题
     */
    @GetMapping("/cancel-judge")
    @RequiresAuthentication
    @RequiresRoles("root")  // 只有超级管理员能操作
    @RequiresPermissions("rejudge")
    public CommonResult<Judge> cancelJudge(@RequestParam("submitId") Long submitId) {
        return rejudgeService.cancelJudge(submitId);
    }

}
